package com.douguo.recipe.network;

import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.util.Xml;

import com.douguo.recipe.HomeActivity;
import com.douguo.recipe.LoadingActivity;
import com.douguo.recipe.RecipelistActivity;
import com.douguo.recipe.object.Caipu;
import com.douguo.recipe.object.Caixi;
import com.douguo.recipe.object.HomeCategory;
import com.douguo.recipe.object.HomeRecipe;
import com.douguo.recipe.object.Kouwei;
import com.douguo.recipe.object.Sort;
import com.douguo.recipe.object.Tese;

public class PrepareHomeCachePhoto {
	private static final String TAG = "GetHomeCachePhoto";

	public static void getHomePhoto() {
		final List<NameValuePair> nvps = new ArrayList<NameValuePair>();
		
		final String url = Constant.URL_GET_HOME_CACHE_PHOTO;
		
		
		new Thread(new Runnable() {

			public void run() {
				DouguoConnection mConn = new DouguoConnection(url, nvps,
						mParseListener, DouguoConnection.GET_METHOD);
				String url= (String) mConn.Connect();
				LoadCachePhoto.getPhoto(url);

			}

		}).start();
	}

	private static OnParseListener mParseListener = new OnParseListener() {

		public Object onParsing(InputStream is) {
			XmlPullParser parser = Xml.newPullParser();
			String url = null;
			boolean done = false;

			try {

				parser.setInput(is, null);
				int eventType = parser.getEventType();
				while (eventType != XmlPullParser.END_DOCUMENT && !done) {
					String name = null;
					switch (eventType) {
					case XmlPullParser.START_DOCUMENT:
						break;
					case XmlPullParser.START_TAG:
						name = parser.getName();
						if (name.equalsIgnoreCase("banner")) {
							url = parser.nextText();
							Log.d(TAG, url);
						}
						break;
					case XmlPullParser.END_TAG:

						break;
					case XmlPullParser.END_DOCUMENT:
						done = true;
						break;
					}
					eventType = parser.next();
				}
			} catch (XmlPullParserException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return url;
		}
		

	};

}
